constraints

Purpose

Allows the definition of declarative validation constraints. See Validation in the user guide.

Examples

class Book {
   String title
   Author author
   static constraints = {
        title(blank:false, nullable:false, size:5..150)	
        author(nullable:false)
   }	
}

Description

Constraints are defined using the declarative constraints DSL as described in the Validation section of the user guide. Once evaluated validation can be applied through the use of the validate method:

def b = new Book()
assert !b.validate()

A list of ConstrainedProperty instances applied against the domain class by the constraints property is available at runtime:

b.constraints.each {
      println it.name
      println it.maxSize
}